package eva.savant.core.printer;

import java.awt.*;
import javax.swing.*;
import javax.print.PrintServiceLookup;

public class PrinterApplet extends JApplet {


    private JLabel printerInfoValue;


    public PrinterApplet() {

        JLabel printerInfo = new JLabel("Impresora Predeterminada : ");

        printerInfoValue = new JLabel("", SwingConstants.CENTER);

        setLayout(new BorderLayout());


        JPanel panel = new JPanel();

        panel.setLayout(new GridLayout(1, 1));

        panel.add(printerInfo);

        panel.add(printerInfoValue);

        getContentPane().add(panel,"North");
    }

    public void init() {

        printerInfoValue.setText(PrintServiceLookup.lookupDefaultPrintService().getName());

		if(getParameter("TxtPrint") != null) TxtPrint();

		if(getParameter("PosPrint") != null) PosPrint();
    }

    public void TxtPrint() {

        try {

            String filePrint= getParameter("TxtPrint");

            filePrint= filePrint.replaceAll("\\|","\n");

            System.out.println("File Print: "+filePrint);

            if(filePrint == null || filePrint.length() < 1) return;


            Printer printer= new Printer(this, filePrint);

			printer.start();

        } catch(Exception exception) {

            JOptionPane.showMessageDialog(this, exception);

            exception.printStackTrace();
        }

    }

	public void PosPrint() {

	}

    public static void main(String arg[]) {

        PrinterApplet printer= new PrinterApplet();

        printer.init();

        JFrame frame= new JFrame();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.getContentPane().add(printer);

        frame.setBounds(100,100,350,100);

        frame.setVisible(true);
    }

}

/*
FileOutputStream out = new FileOutputStream("LPT1");

PrintStream ps = new PrintStream(out);     //80

ps.println ("solely on talking to the ports through the file system. This is the ultimate in \r\n portability. Unfortunately, they have made it extremely difficult to use. They provide files to access their proprietary hardware. Their stuff could be used to \r");

ps.println ("222222222222222222222222222solely on talking to the ports through the file system. This is the ultimate in portability. Unfortunately, they have made it extremely difficult to use. They provide files to access their proprietary hardware. Their stuff could be used to ");

ps.print("\f");

ps.close();
*/

